package com.wfg.nettydemo.io.bio;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author wufagang
 * @description
 * @date 2022年07月23日 16:57
 */
public class TestSocket {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8090);
        System.out.println("step1: new ServerSocket(8090)");
        while (true){
            Socket socket = serverSocket.accept();
            System.out.println("step2: cleient \t"+socket.getPort());

            new Thread(new Runnable() {

                Socket socket;
                public Runnable setSocket(Socket s){
                    this.socket = s;
                    return this;
                }
                @Override
                public void run() {
                    try {
                        InputStream inputStream = socket.getInputStream();
                        BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
                        while (true){
                            System.out.println(br.readLine());
                        }
                    }catch (Exception e){
                        e.printStackTrace();
                    }finally {

                    }
                }
            }.setSocket(socket)).start();
        }
    }
}
